package com.example.mouther_bg.controller;

import com.example.mouther_bg.Bean.Comment;
import com.example.mouther_bg.Bean.Video;
import com.example.mouther_bg.service.commentService;
import com.example.mouther_bg.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
public class commentController {
    @Autowired
    private commentService commentService;
    private Video videoss;
    //    根据id查询相关评论
    @CrossOrigin
    @GetMapping("/queryComment")
    public Result queryComment(int id){
        List<Video> videos = commentService.queryComment(id);
//        List<Video> videos = commentService.queryComment(id);
        if (videos.isEmpty())  {
            return Result.err();
        }
        return Result.succ(videos);
    }
//    对这个视频发表评论
    @CrossOrigin
    @PostMapping("/pushComment")
    public Result pushComment(@RequestBody  Comment comment){
        boolean save = commentService.save(comment);
        if (save){
            return Result.succ("");
        }
        return Result.err();
    }
//    删除评论
    @CrossOrigin
    @GetMapping("/comment/delComment")
    public Result deleteComment(int id){
        boolean b = commentService.removeById(id);
        if(b){
            return Result.succ("");
        }
        return Result.err();
    }
}
